﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;

namespace PmSoft.Caching.Serializers
{
    internal class NetJsonSerializer : ISerializer
    {
        private readonly JsonSerializerOptions serializerOptions;
        private static readonly Encoding encoding = Encoding.UTF8;

        public NetJsonSerializer(JsonSerializerOptions? serializerOptions = null)
        {
            this.serializerOptions = serializerOptions ?? JsonSerializerOptions.Default;
        }

        public object? Deserialize(byte[] serializedObject)
        {
            throw new NotImplementedException();
        }

        public T? Deserialize<T>(byte[] serializedObject)
        {
            throw new NotImplementedException();
        }

        public Task<object?> DeserializeAsync(byte[] serializedObject)
        {
            throw new NotImplementedException();
        }

        public Task<T?> DeserializeAsync<T>(byte[] serializedObject)
        {
            throw new NotImplementedException();
        }

        public byte[] Serialize(object item)
        {
            var type = item.GetType();
            string jsonString = JsonSerializer.Serialize(item, type, serializerOptions);
            return encoding.GetBytes(jsonString);
        }

        public async Task<byte[]> SerializeAsync(object item)
        {
            return await Task.FromResult(Serialize(item));
        }
    }
}
